package com.example.liwushuo.fragment;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.example.liwushuo.R;
import com.example.liwushuo.adapter.UserAdapter;
import com.example.liwushuo.bean.BaseBean;
import com.example.liwushuo.bean.Comment;
import com.example.liwushuo.bean.Data;
import com.example.liwushuo.bean.Datas;
import com.example.liwushuo.bean.UserBase;
import com.example.liwushuo.urls.urls;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class UserTallFragment extends Fragment {

	private ListView listView;
	private List<Comment> list;
	private UserAdapter adapter;
	private long id;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		id = getArguments().getLong("id");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.fragment_user_tall, null);
		initView(view);
		loadData();
		return view;

	}

	private void initView(View view) {
		listView = (ListView) view.findViewById(R.id.user_listView);
		list = new ArrayList<Comment>();
		adapter = new UserAdapter(getActivity(), list);
		listView.setAdapter(adapter);
	}

	private void loadData() {

		HttpUtils httpUtils = new HttpUtils();
		httpUtils.send(HttpMethod.GET, urls.getGoodsInfoTallUrl(id),
				new RequestCallBack<String>() {

					@Override
					public void onFailure(HttpException arg0, String arg1) {
					}

					@Override
					public void onSuccess(ResponseInfo<String> response) {
						String json = response.result;
						UserBase userBean = JSONObject.parseObject(json,
								UserBase.class);
						if (userBean != null
								&& "OK".equals(userBean.getMessage())) {
							list.addAll(userBean.getData().getComments());
							adapter.notifyDataSetChanged();
						}
					}
				});
	}
}
